package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.CompanyBaseDAO;
import com.yang.doctorrecruitment.dao.JobDAO;
import com.yang.doctorrecruitment.dto.CompanyBase;
import com.yang.doctorrecruitment.dto.ReleaseJob;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class ReleaseDetailAction extends ActionSupport {
    private JSON job;
    private JSON company;
    private JSONArray other;
    public String getJobAndCompanyByJobID(){
        HttpServletRequest request= (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
        String JobID=request.getParameter("JobID");
//      这里要获得招聘的信息，公司的信息，以及该公司还发布了哪些招聘信息
        ReleaseJob Job= new ReleaseJob();
        Job.setJobID(JobID);
        boolean res=JobDAO.getReleseJobByJobID(Job);
//        不能同时执行，会出错
//        利用值传递
        if(res) {
            JSONObject Ojson=new JSONObject();
            Ojson.put("JobName",Job.getJobName());
            Ojson.put("JobAddress",Job.getJobAddress());
            Ojson.put("JobNum",Job.getJobNum());
            Ojson.put("JobRequire",Job.getJobRequire());
            Ojson.put("JobSalary",Job.getJobSalary());
            Ojson.put("UserID",Job.getUserID());
            Ojson.put("JobDuty",Job.getJobDuty());
            Ojson.put("PublishTime",Job.getPublishTime());
            job=Ojson;
            System.out.println(Job.getUserID());
            CompanyBase com = CompanyBaseDAO.selectCompany(Job.getUserID());
            JSONObject js=new JSONObject();
            js.put("CompanyName",com.getCompanyName());
            js.put("CompanyCorporation",com.getCompanyCorporation());
            js.put("CompanyAddress",com.getCompanyAddress());
            js.put("CompanyEmail",com.getCompanyEmail());
            js.put("CompanyIntroduce",com.getCompanyIntroduce());
            js.put("CompanyNature",com.getCompanyNature());
            js.put("CompanyScale",com.getCompanyScale());
            js.put("CompanyTelphone",com.getCompanyTelphone());
            js.put("CompanyType",com.getCompanyType());

            js.put("Companylicense",com.getCompanylicense());

            js.put("CompanyIdentified",com.getCompanyIdentified());
            js.put("FilePath",com.getFilePath());

            company=js;
            List<ReleaseJob> list = JobDAO.getReleseJob(Job.getUserID());
            JSONArray array= JSONArray.parseArray(JSON.toJSONString(list));
            other=array;
            return SUCCESS;
        }else{
            return ERROR;
        }

    }
    public JSON getJob() {
        return job;
    }

    public void setJob(JSON job) {
        this.job = job;
    }

    public JSON getCompany() {
        return company;
    }

    public void setCompany(JSON company) {
        this.company = company;
    }

    public JSONArray getOther() {
        return other;
    }

    public void setOther(JSONArray other) {
        this.other = other;
    }
}
